<template>
  <el-dialog title="审批不通过" :close-on-click-modal="false" append-to-body
             :visible.sync="visible" class="JNPF-dialog JNPF-dialog_center" lock-scroll
             width="600px" :before-close="beforeClose">
    <el-row :gutter="15" class="">
      <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="80px" label-position="left">
        <template v-if="!loading">
          <CommonWordsDialog ref="commonWordsDialog" @change="common"/>
          <br>
          <el-form-item label="审批意见" prop="handleOpinion">
            <el-input v-model="dataForm.handleOpinion" placeholder="请输入审批意见" type="textarea"
                      :rows="4"/>

          </el-form-item>
<!--          <el-form-item label="审批附件" prop="fileList">-->
<!--            <JnpfUploadFile v-model="dataForm.fileList" :limit="3"/>-->
<!--          </el-form-item>-->
        </template>
      </el-form>
    </el-row>
    <span slot="footer" class="dialog-footer">
         <el-button @click="visible = false"> 取 消</el-button>
          <el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading"> 确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import CommonWordsDialog from './CommonWordsDialog'
import request from '@/utils/request'
import request2 from '@/utils/request2'

export default {
  name: 'disagreeForm',
  components: {CommonWordsDialog},
  data() {
    return {
      visible: false,
      loading: false,
      dataFormSubmitType: 0,
      btnLoading: false,
      commonWordsVisible: false,
      id:undefined,
      dataForm: {
        suspend: false,
        // branchList: [],
        // candidateList: [],
        fileList: [],
        handleOpinion: ''
      },
      rules: {},
    }

  },
  computed: {},
  watch: {},
  created() {


  },
  mounted() {
  },
  methods: {
    init(id) {
      this.visible = true;
      this.id = id;
    },
    dataList() {
      var _data = JSON.parse(JSON.stringify(this.dataForm));
      // _data.fileList = Array.isArray(_data.fileList) ? JSON.stringify(_data.fileList) : '[]'
      return _data;
    },
    dataFormSubmit(type) {
      let requestData = {
        id: this.id,
        approvalOpinion: this.dataForm.handleOpinion
        // fileList:this.dataForm.fileList
        // // fileList: JSON.parse(JSON.stringify(this.dataForm.fileList))
      };
      this.dataFormSubmitType = type ? type : 0
      this.$refs['elForm'].validate((valid) => {
        if (valid) {
          let _data = this.dataList()
          request({
            url: `/api/workflow/Engine/FlowBefore/Suspend/${this.id}`,
            method: 'post',
            data: _data
          }).then((res) => {
            request2({
              url: `/fzzxqy/splbgqzt`,
              method: 'post',
              data: requestData
            }).then((res2) => {
              this.$message({
                type: res2.success ? 'success' : 'error',
                message: res2.message || '处理成功',
                duration: 1000,
                onClose: () => {
                  this.visible = false
                  this.btnLoading = false
                  this.$emit('refresh', true)
                }
              })
            })
          })
        }
      })
    },
    common(val) {
      this.commonWordsVisible = false
      if (val) {
        if (this.visible) {
          this.dataForm.handleOpinion += val.commonWordsText
        } else {
          this.dataForm.handleOpinion += val.commonWordsText
        }

      }
    },
    beforeClose() {
      this.visible = false
      this.$refs.commonWordsDialog.close()
    },
  }
}
</script>

<style scoped>

</style>
